# coding=utf-8
import socket, ssl, pprint, time
 
HOST = '127.0.0.1'
PORT = 10023
BUFSIZE = 1024
ADDR = (HOST, PORT)
 
# 创建socket套接字
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# 从服务端获取一个CA证书
ssl_sock = ssl.wrap_socket(s, ca_certs="server.crt", cert_reqs=ssl.CERT_REQUIRED)
# socket连接
ssl_sock.connect(ADDR)
 
# note that closing the SSLSocket will also close the underlying socket
pprint.pprint(ssl_sock.getpeercert())
 
while True:
    data = "hello world"
    ssl_sock.send(data)
    data = ssl_sock.recv(BUFSIZE)
    if not data:
        break
    print
    data
ssl_sock.close()

